﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EDMXParserV1;

namespace MVCGenerator
{
    public class DeleteCSHtml
    {
        private SpaceStackStringBuilder sb = new SpaceStackStringBuilder();

        public DeleteCSHtml(String NamespaceName, String PropertyClassName, EntitySet SelectedEntitySet)
        {
            sb.AppendLine("@model " + NamespaceName + "." + PropertyClassName + "");
            sb.AppendLine();
            sb.AppendLine("@{");
            if (true)
            {
                sb.AddSpace();
                sb.AppendLine(@"ViewBag.Title = ""Delete"";");
                sb.RemoveSpace();
            }
            sb.AppendLine("}");
            sb.AppendLine();
            sb.AppendLine("<h2>Delete</h2>");
            sb.AppendLine();
            sb.AppendLine("<h3>Are you sure you want to delete this?</h3>");
            sb.AppendLine("<fieldset>");
            if (true)
            {
                sb.AddSpace();
                sb.AppendLine("<legend>" + PropertyClassName + "</legend>");
                foreach (EDMXParserV1.Property Item in SelectedEntitySet.EntityTypeLink.Properties)
                {
                    //foreach (PublicProperty PP in PropertyClass.Properties)
                    //{

                    if (Item.IsDateTime())
                    {
                        sb.AppendLine();
                        sb.AppendLine(@"<div class=""display-label"">@Html.LabelFor( x => x." + Item.Name + " )</div>");
                        sb.AppendLine(@"<div class=""display-field"">@String.Format(""{0:g}"", Model." + Item.Name + ")</div>");
                    }
                    else
                    {
                        sb.AppendLine();
                        sb.AppendLine(@"<div class=""display-label"">@Html.LabelFor( x => x." + Item.Name + " )</div>");
                        sb.AppendLine(@"<div class=""display-field"">@Model." + Item.Name + "</div>");

                    }

                }
                sb.RemoveSpace();
            }

            sb.AppendLine("</fieldset>");
            sb.AppendLine("@using (Html.BeginForm()) {");
            if (true)
            {
                sb.AddSpace();
                sb.AppendLine("<p>");
                if (true)
                {
                    sb.AddSpace();
                    sb.AppendLine(@"<input type=""submit"" value=""Delete"" /> |");
                    sb.AppendLine(@"@Html.ActionLink(""Back to List"", ""Index"")");
                    sb.RemoveSpace();
                }
                sb.AppendLine("</p>");
                sb.RemoveSpace();
            }
            sb.AppendLine("}");
        }

        public override string ToString()
        {
            return sb.ToString();
        }
    }
}
